package com.yphone.ui.remote.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

import com.iiordanov.bVNC.Constants;
import com.iiordanov.bVNC.RemoteCanvas;
import com.iiordanov.bVNC.Utils;

public class RemoteCanvasActivity extends AppCompatActivity {
    private RemoteCanvas canvas;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        Utils.showMenu(this);

        setContentView(com.undatech.remoteClientUi.R.layout.canvas);

        canvas = (RemoteCanvas) findViewById(com.undatech.remoteClientUi.R.id.canvas);
        if (android.os.Build.VERSION.SDK_INT >= 9) {
            android.os.StrictMode.ThreadPolicy policy = new android.os.StrictMode.ThreadPolicy.Builder().permitAll().build();
            android.os.StrictMode.setThreadPolicy(policy);
        }

        View decorView = getWindow().getDecorView();
//        decorView.setOnSystemUiVisibilityChangeListener
//                (new View.OnSystemUiVisibilityChangeListener() {
//                    @Override
//                    public void onSystemUiVisibilityChange(int visibility) {
//                        try {
//                            correctAfterRotation();
//                        } catch (Exception e) {
//                            //e.printStackTrace();
//                        }
//                        //handler.postDelayed(rotationCorrector, 300);
//                    }
//                });
//
//        Runnable setModes = new Runnable() {
//            public void run() {
//                try {
//                    setModes();
//                } catch (NullPointerException e) {
//                }
//            }
//        };

    }

    /**
     * This function is called by the rotationCorrector runnable
     * to fix things up after a rotation.
     */
//    private void correctAfterRotation() throws Exception {
//        canvas.waitUntilInflated();
//        // Its quite common to see NullPointerExceptions here when this function is called
//        // at the point of disconnection. Hence, we catch and ignore the error.
//        float oldScale = canvas.canvasZoomer.getZoomFactor();
//        int x = canvas.absoluteXPosition;
//        int y = canvas.absoluteYPosition;
//        canvas.canvasZoomer.setScaleTypeForActivity(com.iiordanov.bVNC.RemoteCanvasActivity.this);
//        float newScale = canvas.canvasZoomer.getZoomFactor();
//        canvas.canvasZoomer.changeZoom(this, oldScale / newScale, 0, 0);
//        newScale = canvas.canvasZoomer.getZoomFactor();
//        if (newScale <= oldScale &&
//                canvas.canvasZoomer.getScaleType() != ImageView.ScaleType.FIT_CENTER) {
//            canvas.absoluteXPosition = x;
//            canvas.absoluteYPosition = y;
//            canvas.resetScroll();
//        }
//        if (canvas.isVnc && connection.getRdpResType() == Constants.VNC_GEOM_SELECT_AUTOMATIC) {
//            canvas.rfbconn.requestResolution(canvas.getWidth(), canvas.getHeight());
//        }
//    }

}
